package com.yunang.officialweb.service.impl;

import com.yunang.officialweb.entity.Footer;
import com.yunang.officialweb.mapper.FooterMapper;
import com.yunang.officialweb.service.FooterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FooterServiceImpl implements FooterService {

    @Resource
    private FooterMapper footerMapper;

    @Override
    public Map<String, Object> selectFooter(){
        Map<String, Object> footerMap = new HashMap<>();
        String[] str = new String[4];

        List<Map<String, String>> list = new ArrayList<>();
        String[] name = {"首页","近期产品","关于我们","加入我们"};
        String[] path = {"/home","/product","/aboutUs","/joinUs"};

        for (int i = 0; i<4; i++){
            Map<String, String> map = new HashMap<>();
            map.put("name", name[i]);
            map.put("path", path[i]);
            list.add(map);
        }
        Footer footer = footerMapper.selectFooter();
        str[0] = "官方QQ:"+footer.getQq();
        str[1] = "官方微信:"+footer.getWeixin();
        str[2] = "官方邮箱:"+footer.getEmail();
        str[3] = "官方公众号:"+footer.getOfficialAccount();

        footerMap.put("navigationTitle", footer.getNavigationTitle());
        footerMap.put("image",footer.getImage());
        footerMap.put("contactUsTitle", footer.getContactUsTitle());
        footerMap.put("contactUs", str);
        footerMap.put("QRcode", footer.getQRcode());
        footerMap.put("navigation", list);

        return footerMap;
    }

    @Override
    public  Boolean updateFooter( Footer footer){
        footer.setId(1);
        return footerMapper.updateFooter(footer);
    }

}
